﻿#ifndef __RANK_LIST_H_
#define __RANK_LIST_H_

// ==============================================================================
//  排行榜
// ------------------------------------------------------------------------------


#include "../share/user_define.h"
#include "../../3rd/libjson/json.h"
#include "GameObject.h"

#include <map>
#include <vector>

#include "Player.h"

// ------------------------------------------------------------------------------
//	排行榜成员数据
struct stRankMemberDate
{
	static uint8_t const NameStrLen = 32;

	uint32_t    mAccountId;
	uint32_t 	mPlayerId;
	uint32_t 	mPlayerPhoto;
	uint32_t	mPlayerPhotoBox;
	uint32_t 	mPlayerLevel;
	char     	mPlayerName[NameStrLen];
	char     	mPlayerTitle[NameStrLen];
	char     	mPlayerGuildName[NameStrLen];
	uint32_t	mValueCurrent;		//排行数值
	uint32_t 	mRankingCurrent;	//当前排名
	uint32_t	mRankYesterday;		//昨日排名
	uint32_t 	mRankType;
	std::string mRankNote;
	uint32_t    mFc;//战力值

	//创建对象后，调用
	void clear()
	{
		mAccountId = 0;
		mPlayerId = 0;
		mPlayerPhoto = 0;
		mPlayerPhotoBox = 0;
		mPlayerLevel = 0;
		_mem_zero(mPlayerName, NameStrLen);
		_mem_zero(mPlayerTitle, NameStrLen);
		_mem_zero(mPlayerGuildName, NameStrLen);
		mValueCurrent = 0;	
		mRankingCurrent = 0;
		mRankYesterday = 0;	
		mRankType = 0;
		mRankNote = "";
		mFc = 0;
	}

	const stRankMemberDate& operator=(const stRankMemberDate& stObj)
	{
		if (this != &stObj)
		{
			mAccountId			= stObj.mAccountId;
			mPlayerId			= stObj.mPlayerId;
			mPlayerPhoto		= stObj.mPlayerPhoto;
			mPlayerPhotoBox		= stObj.mPlayerPhotoBox;
			mPlayerLevel		= stObj.mPlayerLevel;
			mValueCurrent		= stObj.mValueCurrent;		//排名数值
			mRankingCurrent		= stObj.mRankingCurrent;	//当前排名
			mRankYesterday		= stObj.mRankYesterday;		//昨日排名
			mRankType			= stObj.mRankType;
			mRankNote			= stObj.mRankNote;
			mFc					= stObj.mFc;

			strncpy(mPlayerName, stObj.mPlayerName
				, _array_size(mPlayerName));
			strncpy(mPlayerTitle, stObj.mPlayerTitle
				, _array_size(mPlayerTitle));
			strncpy(mPlayerGuildName, stObj.mPlayerGuildName
				, _array_size(mPlayerGuildName));

		}

		return *this;
	}
};

// ------------------------------------------------------------------------------
//	排行榜模板定义
class RankingList 
	: public GameObject
{
	static uint8_t const NameStrLen = 32;
	static uint32_t const max_hero_rankshow = 10;

public:
	//---------------------------------------------------------------------------
	RankingList();
	//---------------------------------------------------------------------------
	~RankingList();

public:
	//---------------------------------------------------------------------------
	void Clear();

public:
	//---------------------------------------------------------------------------
	void init();
	//---------------------------------------------------------------------------
	void UpdateRankListDataAtRegular(std::string& rData
		, uint32_t start, uint32_t count);
	//---------------------------------------------------------------------------
	//	获取排行榜单区间
	void GetOrderedRankListByErea(uint32_t typeId
		, int32_t minRanking, int32_t maxRanking, Json::Value& jv);
	//---------------------------------------------------------------------------
	uint32_t GetRankingByPlayerId(uint32_t playerId);

	//---------------------------------------------------------------------------
	//	更新有序榜单
	void AddMemberToTimingList(std::string memberInfo);
	void SetTimingListIsUpdated(uint32_t state);


public:
	std::vector<stRankMemberDate>			m_vecRankFixed;	//有序榜单
	std::vector<stRankMemberDate>			m_vecTiming;	//实时有序
	uint32_t								m_isUpdated;	//1:已有更新

	uint32_t 	m_rankType;
	char 		m_rankName[NameStrLen];	
	uint32_t 	m_updateTime;
	uint32_t 	m_showCount;
	uint32_t 	m_rankingBufferIdx;
	uint32_t	m_valueLimit;//入榜数值限定
	uint32_t 	m_scriptId;
};

#endif//  !__RANK_LIST_H_